package com.wangxiang.shop.product.utils;

import com.wangxiang.shop.product.entity.SkuEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
public class SkuUtil {
    //返回style-size集合的烦发，功能是库存属性排重
    public HashMap<String, List<String>> getStyleSizeImgList(List<SkuEntity> list){
        if (list.size()!=0){
            HashMap<String, List<String>> map = new HashMap<>();
            ArrayList<String> styleList = new ArrayList<>();
            ArrayList<String> sizeList = new ArrayList<>();
            ArrayList<String> imgList = new ArrayList<>();
            for (SkuEntity skuEntity : list) {
                if (skuEntity.getStyle()!=null){
                    if (!styleList.contains(skuEntity.getStyle())){
                        styleList.add(skuEntity.getStyle());
//                        System.out.println("颜色"+skuEntity.getStyle());
                    }
                }
                if (skuEntity.getSize()!=null){
                    if (!sizeList.contains(skuEntity.getSize())){
                        sizeList.add(skuEntity.getSize());
//                        System.out.println("size"+skuEntity.getSize());
                    }
                }
                if (skuEntity.getImage()!=null){
                    if (!imgList.contains(skuEntity.getImage())){
                        imgList.add(skuEntity.getImage());
                    }
                }
            }
            map.put("styleList",styleList);
            map.put("sizeList",sizeList);
            map.put("imgList",imgList);
            return map;

        }
        return null;
    }
}
